Welcome to “File and Directory Navigation
Commands.” In this video, you will learn how to: Use the “list” command to list a directory’s
contents Navigate between different directories with
the “change directory” command Explain relative and absolute paths, and Find files with the “find” command The ls or “list” command will list
the files and directories within a directory. If you enter “ls” in your home directory,
you will see all the files and directories that your home directory contains. You can also pass a directory name, such as
“Downloads,” as a parameter to ls, which will list the contents of your Downloads
folder. The ls command also supports options
that will list additional information. Suppose you’re currently working in your
documents folder, and you want more information about the files within the directory. You can use the ls command with the
-l option, which will show child files and directories in a longer, more detailed
format. You can see that the terminal has listed all
the child files, directories, and additional details, such as permissions, last-modified
date, and owner. At times, you may need to know which directory
you’re currently working in. In these cases, you can use the “print working
directory” command to get your current working directory. Enter "pwd" into the command line to
use the command. Here you can see that you’re currently working
in your home directory, “/Users/me.” If you want to change your current working
directory, you can use the “change directory” command. The “change directory,” or cd
command, is used to change the directory you are working in. Suppose you’re in your home directory and
wish to move to a subdirectory within it, such as the Documents folder. Simply enter “cd Documents” to change
your working directory. Now, if you enter “pwd,” you can see that you’re now working in your
Documents subdirectory. The cd command enables you to change
directories with either a relative or an absolute path. Let’s say you’re in a “Notes” folder
within your “Documents” directory tree. To get to the parent directory relative to
your current folder, enter the cd command with the relative path symbol “..”
as its argument. Now your working directory is “Math,”
the immediate parent directory of your “Notes” folder. If you want to navigate directly to your home
folder, use the tilde symbol with the cd command. This will take you to your home folder. In
this case, the tilde symbol represents an absolute path to home. Finally, you can also provide a full path
to a directory. Here you are referring to the absolute pathname for the original “Notes”
directory. As expected, this command will take you back
to the “Notes” folder where you started. Lastly, the “find” command is a powerful
tool that will return the path to every file that matches a user-specified criterion. Suppose your “Documents” folder has a
file structure as shown, two subfolders, each containing a few files. Let’s say you’re working in your “Documents”
folder and want to find the paths of all files named “a.txt” within your working
directory. To do so, type “find . -name ‘a.txt’.” The “.” argument means “search within
here,” so the command will only search within your current working directory. To perform a case-insensitive version of your
search, you can use the “-iname” option instead. You’ll see that you find the same file,
plus another file with the same name but with an uppercase “A.” In this video, you learned that: The ls command lists all files and
directories contained within a specified directory tree The cd command is used to navigate
between directories Relative paths are relative to your current
working directory, while absolute paths stand independently The find command is used to find files
in your directories